package conf2.ui;

import conf2.model.GameType;
import conf2.model.ShelobRule;
import conf2.model.SpecialCardRule;
import conf2.text.Misc;
import conf2.ui.InputValidator;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.JTextField;
import javax.swing.KeyStroke;

public class StartServerDialog extends javax.swing.JDialog
{

    public static class ReturnValue
    {

        public final String name;
        public final int portNumber;
        public final ShelobRule shelobRule;
        public final SpecialCardRule specialCardRule;
        public final GameType gameType;

        public ReturnValue(String name, int portNumber, ShelobRule shelobRule, SpecialCardRule specialCardRule, GameType gameType)
        {
            this.name = name;
            this.portNumber = portNumber;
            this.shelobRule = shelobRule;
            this.specialCardRule = specialCardRule;
            this.gameType = gameType;
        }

        @Override
        public String toString()
        {
            return String.format("Name: %s, port: %d\nGame type: %s, Special card rule: %s, Shelob rule: %s",
                    name, portNumber, gameType, specialCardRule, shelobRule);
        }
    }
    private ReturnValue returnValue = null;

    public static ReturnValue show(java.awt.Frame parent,
            String name,
            int port,
            GameType gameType,
            SpecialCardRule specialCardRule,
            ShelobRule shelobRule)
    {
        StartServerDialog dlg = new StartServerDialog(parent, name, port, gameType, specialCardRule, shelobRule);
        dlg.setVisible(true);
        return dlg.returnValue;
    }

    /** Creates new form StartServerDialog */
    private StartServerDialog(java.awt.Frame parent,
            String name,
            int port,
            GameType gameType,
            SpecialCardRule specialCardRule,
            ShelobRule shelobRule)
    {
        super(parent, true);
        initComponents();

        FrameUtil.bindKey(this, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), new AbstractAction()
        {

            public void actionPerformed(ActionEvent e)
            {
                cancelButtonActionPerformed(null);
            }
        });

        InputValidator.bind(nameField, okButton, InputValidator.NAME_RESTRICTION);
        InputValidator.bind(portField, okButton, InputValidator.PORT_RESTRICTION);

        FocusListener focusListener = new FocusAdapter()
        {

            @Override
            public void focusGained(FocusEvent e)
            {
                JTextField f = (JTextField) e.getSource();
                f.setSelectionStart(0);
                f.setSelectionEnd(f.getText().length());
            }
        };

        nameField.addFocusListener(focusListener);
        portField.addFocusListener(focusListener);

        nameField.setText(name);
        portField.setText(String.valueOf(port));

        nameField.requestFocusInWindow();

        switch (gameType) {
            case CLASSIC:
                classicRadioActionPerformed(null);
                classicRadio.setSelected(true);
                break;
            case VARIANT:
                variantRadioActionPerformed(null);
                variantRadio.setSelected(true);
                break;
            case DRAFT:
                draftRadioActionPerformed(null);
                draftRadio.setSelected(true);
                break;
        }

        switch (shelobRule) {
            case SHELOB_DIES:
                shelobDiesRadioActionPerformed(null);
                shelobDiesRadio.setSelected(true);
                break;
            case SHELOB_FIGHTS:
                shelobFightsRadioActionPerformed(null);
                shelobFightsRadio.setSelected(true);
                break;
            case SHELOB_STAYS:
                shelobStaysRadioActionPerformed(null);
                shelobStaysRadio.setSelected(true);
                break;
        }

        switch (specialCardRule) {
            case CLASSIC:
                classicSpecialCardRadioActionPerformed(null);
                classicSpecialCardRadio.setSelected(true);
                break;
            case FELLOWSHIPS_CHOICE:
                fellowshipsChoiceRadioActionPerformed(null);
                fellowshipsChoiceRadio.setSelected(true);
                break;
            case TWO_OUT_OF_FOUR:
                twoOfFourRadioActionPerformed(null);
                twoOfFourRadio.setSelected(true);
                break;
        }

        getRootPane().setDefaultButton(okButton);
        setLocationRelativeTo(parent);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        generalPanel = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        portLabel = new javax.swing.JLabel();
        portField = new javax.swing.JTextField();
        gameTypePanel = new javax.swing.JPanel();
        classicRadio = new javax.swing.JRadioButton();
        variantRadio = new javax.swing.JRadioButton();
        draftRadio = new javax.swing.JRadioButton();
        gameTypeLabel = new javax.swing.JLabel();
        specialCardRulePanel = new javax.swing.JPanel();
        classicSpecialCardRadio = new javax.swing.JRadioButton();
        twoOfFourRadio = new javax.swing.JRadioButton();
        fellowshipsChoiceRadio = new javax.swing.JRadioButton();
        specialCardLabel = new javax.swing.JLabel();
        shelobRulePanel = new javax.swing.JPanel();
        shelobDiesRadio = new javax.swing.JRadioButton();
        shelobFightsRadio = new javax.swing.JRadioButton();
        shelobStaysRadio = new javax.swing.JRadioButton();
        shelobRuleLabel = new javax.swing.JLabel();
        buttonPanel = new javax.swing.JPanel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        titleLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(Misc.START_SERVER_DLG_CAPTION        );

        generalPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(Misc.START_SERVER_DLG_GENERAL));
        generalPanel.setLayout(new java.awt.GridBagLayout());

        nameLabel.setText(Misc.YOUR_NAME_LABEL);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        generalPanel.add(nameLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.8;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10);
        generalPanel.add(nameField, gridBagConstraints);

        portLabel.setText(Misc.PORT_NUMBER_LABEL);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        generalPanel.add(portLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.8;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
        generalPanel.add(portField, gridBagConstraints);

        gameTypePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(Misc.START_SERVER_DLG_GAME_TYPE));

        buttonGroup1.add(classicRadio);
        classicRadio.setText(Misc.GAME_TYPE_CLASSIC_NAME);
        classicRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                classicRadioActionPerformed(evt);
            }
        });

        buttonGroup1.add(variantRadio);
        variantRadio.setText(Misc.GAME_TYPE_VARIANT_NAME                );
        variantRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                variantRadioActionPerformed(evt);
            }
        });

        buttonGroup1.add(draftRadio);
        draftRadio.setText(Misc.GAME_TYPE_DRAFT_NAME        );
        draftRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                draftRadioActionPerformed(evt);
            }
        });

        gameTypeLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout gameTypePanelLayout = new javax.swing.GroupLayout(gameTypePanel);
        gameTypePanel.setLayout(gameTypePanelLayout);
        gameTypePanelLayout.setHorizontalGroup(
            gameTypePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gameTypePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(gameTypePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(classicRadio)
                    .addComponent(variantRadio)
                    .addComponent(draftRadio))
                .addGap(10, 10, 10)
                .addComponent(gameTypeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                .addContainerGap())
        );
        gameTypePanelLayout.setVerticalGroup(
            gameTypePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gameTypePanelLayout.createSequentialGroup()
                .addGroup(gameTypePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gameTypePanelLayout.createSequentialGroup()
                        .addComponent(classicRadio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(variantRadio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(draftRadio))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, gameTypePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(gameTypeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)))
                .addContainerGap())
        );

        specialCardRulePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(Misc.START_SERVER_DLG_SPECIALCARD_RULE));

        buttonGroup2.add(classicSpecialCardRadio);
        classicSpecialCardRadio.setText(Misc.SPECIALCARD_RULE_CLASSIC_NAME);
        classicSpecialCardRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                classicSpecialCardRadioActionPerformed(evt);
            }
        });

        buttonGroup2.add(twoOfFourRadio);
        twoOfFourRadio.setText(Misc.SPECIALCARD_RULE_TWO_OF_FOUR_NAME);
        twoOfFourRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                twoOfFourRadioActionPerformed(evt);
            }
        });

        buttonGroup2.add(fellowshipsChoiceRadio);
        fellowshipsChoiceRadio.setText(Misc.SPECIALCARD_RULE_FELLOWSHIPS_CHOICE_NAME);
        fellowshipsChoiceRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fellowshipsChoiceRadioActionPerformed(evt);
            }
        });

        specialCardLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout specialCardRulePanelLayout = new javax.swing.GroupLayout(specialCardRulePanel);
        specialCardRulePanel.setLayout(specialCardRulePanelLayout);
        specialCardRulePanelLayout.setHorizontalGroup(
            specialCardRulePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(specialCardRulePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(specialCardRulePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(classicSpecialCardRadio)
                    .addComponent(twoOfFourRadio)
                    .addComponent(fellowshipsChoiceRadio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(specialCardLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                .addContainerGap())
        );
        specialCardRulePanelLayout.setVerticalGroup(
            specialCardRulePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(specialCardRulePanelLayout.createSequentialGroup()
                .addGroup(specialCardRulePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(specialCardRulePanelLayout.createSequentialGroup()
                        .addComponent(classicSpecialCardRadio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(twoOfFourRadio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fellowshipsChoiceRadio))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, specialCardRulePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(specialCardLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)))
                .addContainerGap())
        );

        shelobRulePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(Misc.START_SERVER_DLG_SHELOB_RULE));

        buttonGroup3.add(shelobDiesRadio);
        shelobDiesRadio.setSelected(true);
        shelobDiesRadio.setText(Misc.SHELOB_RULE_DIES_NAME);
        shelobDiesRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shelobDiesRadioActionPerformed(evt);
            }
        });

        buttonGroup3.add(shelobFightsRadio);
        shelobFightsRadio.setText(Misc.SHELOB_RULE_FIGHTS_NAME);
        shelobFightsRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shelobFightsRadioActionPerformed(evt);
            }
        });

        buttonGroup3.add(shelobStaysRadio);
        shelobStaysRadio.setText(Misc.SHELOB_RULE_STAYS_NAME);
        shelobStaysRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shelobStaysRadioActionPerformed(evt);
            }
        });

        shelobRuleLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout shelobRulePanelLayout = new javax.swing.GroupLayout(shelobRulePanel);
        shelobRulePanel.setLayout(shelobRulePanelLayout);
        shelobRulePanelLayout.setHorizontalGroup(
            shelobRulePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(shelobRulePanelLayout.createSequentialGroup()
                .addGroup(shelobRulePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(shelobDiesRadio)
                    .addComponent(shelobFightsRadio)
                    .addComponent(shelobStaysRadio))
                .addGap(18, 18, 18)
                .addComponent(shelobRuleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                .addContainerGap())
        );
        shelobRulePanelLayout.setVerticalGroup(
            shelobRulePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(shelobRulePanelLayout.createSequentialGroup()
                .addComponent(shelobDiesRadio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(shelobFightsRadio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(shelobStaysRadio)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, shelobRulePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(shelobRuleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                .addGap(10, 10, 10))
        );

        okButton.setText(Misc.OK_BUTTON_LABEL);
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText(Misc.CANCEL_BUTTON_LABEL);
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
        buttonPanel.setLayout(buttonPanelLayout);
        buttonPanelLayout.setHorizontalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
                .addContainerGap(537, Short.MAX_VALUE)
                .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2))
        );
        buttonPanelLayout.setVerticalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        titleLabel.setFont(FontSet.getDraftCaption());
        titleLabel.setText(Misc.START_SERVER_DLG_CAPTION);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(specialCardRulePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(generalPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(shelobRulePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(gameTypePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 633, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(generalPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                    .addComponent(gameTypePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(shelobRulePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(specialCardRulePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fellowshipsChoiceRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fellowshipsChoiceRadioActionPerformed
        specialCardLabel.setText("<html>" + Misc.SPECIALCARD_RULE_FELLOWSHIPS_CHOICE_DESCR + "</html>");
}//GEN-LAST:event_fellowshipsChoiceRadioActionPerformed

    private void shelobDiesRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shelobDiesRadioActionPerformed
        shelobRuleLabel.setText("<html>" + Misc.SHELOB_RULE_DIES_DESCR + "</html>");
}//GEN-LAST:event_shelobDiesRadioActionPerformed

    private void shelobFightsRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shelobFightsRadioActionPerformed
        shelobRuleLabel.setText("<html>" + Misc.SHELOB_RULE_FIGHTS_DESCR + "</html>");
    }//GEN-LAST:event_shelobFightsRadioActionPerformed

    private void shelobStaysRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shelobStaysRadioActionPerformed
        shelobRuleLabel.setText("<html>" + Misc.SHELOB_RULE_STAYS_DESCR + "</html>");
    }//GEN-LAST:event_shelobStaysRadioActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        returnValue = null;
        setVisible(false);
}//GEN-LAST:event_cancelButtonActionPerformed

    private void classicRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_classicRadioActionPerformed
        gameTypeLabel.setText("<html>" + Misc.GAME_TYPE_CLASSIC_DESCR + "</html>");
    }//GEN-LAST:event_classicRadioActionPerformed

    private void variantRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_variantRadioActionPerformed
        gameTypeLabel.setText("<html>" + Misc.GAME_TYPE_VARIANT_DESCR + "</html>");
    }//GEN-LAST:event_variantRadioActionPerformed

    private void draftRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_draftRadioActionPerformed
        gameTypeLabel.setText("<html>" + Misc.GAME_TYPE_DRAFT_DESCR + "</html>");
    }//GEN-LAST:event_draftRadioActionPerformed

    private void classicSpecialCardRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_classicSpecialCardRadioActionPerformed
        specialCardLabel.setText("<html>" + Misc.SPECIALCARD_RULE_CLASSIC_DESCR + "</html>");
    }//GEN-LAST:event_classicSpecialCardRadioActionPerformed

    private void twoOfFourRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_twoOfFourRadioActionPerformed
        specialCardLabel.setText("<html>" + Misc.SPECIALCARD_RULE_TWO_OF_FOUR_DESCR + "</html>");
    }//GEN-LAST:event_twoOfFourRadioActionPerformed

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        String name = nameField.getText().trim();
        int portNumber = Integer.valueOf(portField.getText());

        ShelobRule shRule;
        if (shelobDiesRadio.isSelected()) {
            shRule = ShelobRule.SHELOB_DIES;
        } else if (shelobFightsRadio.isSelected()) {
            shRule = ShelobRule.SHELOB_FIGHTS;
        } else if (shelobStaysRadio.isSelected()) {
            shRule = ShelobRule.SHELOB_STAYS;
        } else {
            throw new RuntimeException("No Shelob rule selected!");
        }

        GameType gmType;
        if (classicRadio.isSelected()) {
            gmType = GameType.CLASSIC;
        } else if (variantRadio.isSelected()) {
            gmType = GameType.VARIANT;
        } else if (draftRadio.isSelected()) {
            gmType = GameType.DRAFT;
        } else {
            throw new RuntimeException("No game type selected!");
        }

        SpecialCardRule cardRule;
        if (classicSpecialCardRadio.isSelected()) {
            cardRule = SpecialCardRule.CLASSIC;
        } else if (twoOfFourRadio.isSelected()) {
            cardRule = SpecialCardRule.TWO_OUT_OF_FOUR;
        } else if (fellowshipsChoiceRadio.isSelected()) {
            cardRule = SpecialCardRule.FELLOWSHIPS_CHOICE;
        } else {
            throw new RuntimeException("No special card rule selected!");
        }

        returnValue = new ReturnValue(name, portNumber, shRule, cardRule, gmType);

        setVisible(false);
    }//GEN-LAST:event_okButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton cancelButton;
    private javax.swing.JRadioButton classicRadio;
    private javax.swing.JRadioButton classicSpecialCardRadio;
    private javax.swing.JRadioButton draftRadio;
    private javax.swing.JRadioButton fellowshipsChoiceRadio;
    private javax.swing.JLabel gameTypeLabel;
    private javax.swing.JPanel gameTypePanel;
    private javax.swing.JPanel generalPanel;
    private javax.swing.JTextField nameField;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JButton okButton;
    private javax.swing.JTextField portField;
    private javax.swing.JLabel portLabel;
    private javax.swing.JRadioButton shelobDiesRadio;
    private javax.swing.JRadioButton shelobFightsRadio;
    private javax.swing.JLabel shelobRuleLabel;
    private javax.swing.JPanel shelobRulePanel;
    private javax.swing.JRadioButton shelobStaysRadio;
    private javax.swing.JLabel specialCardLabel;
    private javax.swing.JPanel specialCardRulePanel;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JRadioButton twoOfFourRadio;
    private javax.swing.JRadioButton variantRadio;
    // End of variables declaration//GEN-END:variables
}
